home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / SAT 2.3.8 / Demos / StepPlatform Demo ƒ / EmptyPlatform.c < prev    next >
Text File  |  1996-05-11  |  2KB  |  74 lines

  1. /* Platform sprite, experimental faceless sprite */
  2.  
  3. #include "SAT.h"
  4. #include "myPlatform.h"
  5.  
  6. void InitEmptyPlatform()
  7. {
  8. /* nada*/
  9. }
  10.  
  11. pascal void SetupEmptyPlatform(SpritePtr me)
  12. {
  13.     Rect            r;
  14.     PolyHandle    pol;
  15.     
  16.     me->task = &HandlePlatform;
  17.     me->hitTask = (void *)&HitPlatform;
  18.  
  19.     me->face = nil; /* = faceless! */
  20.     SetRect(&(me->hotRect), 0, 0, gSAT.offSizeH-150, 16);
  21.     
  22.     me->layer = -me->position.v;
  23. }
  24.  
  25. pascal void HandleEmptyPlatform(SpritePtr me)
  26. {
  27.     /*me->face = nil;*/ 
  28. }
  29.  
  30. pascal void HitEmptyPlatform(SpritePtr me, PlSpritePtr him)
  31. {
  32.     int    mini, i, min;
  33.     int    diff[5];
  34.     
  35.     if (him->task == (void *)HandlePlayerSprite){
  36.         diff[1] = -me->hotRect2.top + (him->hotRect2.bottom);        /* TtoB */
  37.         diff[2] = -him->hotRect2.top + (me->hotRect2.bottom);         /* BtoT */
  38.         diff[3] = -me->hotRect2.left + (him->hotRect2.right);        /* LtoR */
  39.         diff[4] = -him->hotRect2.left + (me->hotRect2.right);        /* RtoL */
  40.         mini = 0;
  41.         min = 10000;
  42.         for(i = 1; i <= 4 ; i++){
  43.             if(min > diff[i]){
  44.                 min = diff[i];
  45.                 mini = i;
  46.             } /* if */
  47.         }
  48.         switch(mini){
  49.             case 1: /*floor*/
  50.                     him->action = Stand;
  51.                     him->position.v = him->position.v - diff[1] + 1; 
  52.                     if(him->speed.v > 0)
  53.                         him->speed.v = 0;
  54.                     him->speed.h = 0;
  55.                     break;
  56.             case 2: /* ceiling */
  57.                     him->position.v = him->position.v + diff[2] + 1;
  58.                     if(him->speed.v < 0)
  59.                         him->speed.v = -him->speed.v;
  60.                     break;
  61.             case 3: /*left*/
  62.                     him->position.h = him->position.h - diff[3] - 1;
  63.                                 if(him->speed.h > 0)
  64.                         him->speed.h = -him->speed.h;
  65.                     break;
  66.             case 4: /*right*/
  67.                     him->position.h = him->position.h + diff[4] + 1;
  68.                     if(him->speed.h < 0)
  69.                         him->speed.h = -him->speed.h;
  70.                     break;
  71.         } /* switch */
  72.     }
  73. }
  74.